
<?php if(isset($isInsert) && $isInsert){
?>
<script>
	ajax('listContent','<?php echo $this->params['controller']?>/lists');
	closeBox('addContent','mainContent');
</script>
<?php
}
else{
?>
<fieldset>
    <legend><?php _resource('edit'. $this->params['controller']);?></legend>
<center><div id="message">&nbsp;</div></center>
<?php if($this->Session->read('message')){
	echo '<script>showMessage("addContent","'.$this->Session->read('message').'");</script>';
	$this->Session->delete('message');	
	}?>
<?php if($this->Session->read('error')){
	echo '<script>showMessage("addContent","'.$this->Session->read('error').'",1);</script>';
	$this->Session->delete('error');
}?>
    <form id="adminForm" name="adminForm" method="post" action="<?php echo $this->params['controller']?>/edit/<?php echo $this->data[$uses[0]]['id']?>" onsubmit="onFormSubmit();return false;">
    <?php 
    echo $this->Form->hidden($uses[0].'.id');
    echo $this->Form->hidden($uses[0].'.oldimage');
    ?>
	<table border="0" class="form" style="width:100%">        
		
		<tr>          
       		<td class="label" align="right" width="100px"><?php _resource('name') ?>
       		
       		</td>
       		<td align="left"><?php echo $this->Form->input($uses[0].'.name',array('class'=>'input','label'=>'','size'=>60,'maxlength'=>255));?></td>           
        </tr> 
        
        <?php if(isset($this->data[$uses[0]]['oldimage'])&& !empty($this->data[$uses[0]]['image'])){?>
        <tr>          
       		<td class="label" align="right" width="100px"><?php _resource('old image') ?></td>
       		<td align="left"><img style="opacity: 1;" src="<?php echo $this->webroot.'uploaded/'.$uses[0].'/thumb/'.$this->data[$uses[0]]['oldimage'] ?>"></td>
       	</tr>
       	<?php }?>
             
		<tr>          
       		<td class="label" align="right" width="100px"><?php _resource('new image') ?>
       		
       		</td>
       		<td align="left"><?php echo $this->Form->hidden($uses[0].'.image',array('class'=>'input','label'=>'','size'=>60,'maxlength'=>255));?>
       		<div id="divUploadContainer" style="">
       		<?php if(isset($this->data[$uses[0]]['image'])&& !empty($this->data[$uses[0]]['image'])){?>
       			<img style="opacity: 1;" src="<?php echo $this->webroot.'uploaded/'.$uses[0].'/image/'.$this->data[$uses[0]]['image'] ?>">
       		<?php }?>
       		</div>
       		<div style="width: 80px; height: 18px; border: solid 1px #7FAAFF; background-color: #C5D9FF; padding: 2px;">
					<span id="spanButtonPlaceholder"></span>
				</div>     
				<div class="fieldset flash" id="divFileProgressContainer"></div>      
        	</td>
        </tr>  
        
        <tr>          
       		<td class="label" align="right" width="100px"><?php _resource('is default') ?>
       		
       		</td>
       		<td align="left"><?php echo $this->Form->checkbox($uses[0].'.default',array('class'=>'input'));?></td>           
        </tr> 
	</table>
	<center>
    <div style="width:130px">
          <div class="button"><a onclick="onFormSubmit()" href="javascript:;" title="<?php echo _resource('save') ?>"  > <span class="icon-32-save"> </span></a> </div>         
          <div class="button"><a onclick="resetForm('adminForm')" href="javascript:;" title="<?php echo _resource('reset') ?>"  > <span class="icon-32-back"> </span></a> </div>
          <div class="button"><a onclick="deactivateEditors();closeBox('addContent','mainContent')" href="javascript:;" title="<?php echo _resource('close') ?>"  > <span class="icon-32-cancel"> </span></a> </div>
    </div>
    </center>
      </form>
</fieldset>

<script>
function onFormSubmit(){
	deactivateEditors();
	submitForm('adminForm','addContent');
}

swfu = new SWFUpload({	      
	// Backend Settings
	upload_url: "<?php echo BACKEND_URL.'fileuploads/imageupload/image/'.$uses[0]?>",
	post_params: {"PHPSESSID": "<?php echo session_id(); ?>"},

	// File Upload Settings
	/*
		file_size_limit: "100 KB" // kilobytes
		file_size_limit: "10000 b" // bytes
		file_size_limit: "25mb" // megabytes
		file_size_limit: "2 gb" // gigabytes
		file_size_limit: "342222" // kilobytes
	*/
	file_size_limit : "5 MB",
	file_types : "*.jpg; *.png; *.gif",
	file_types_description : "Images",
	file_upload_limit : 0,

	// Event Handler Settings - these functions as defined in Handlers.js
	//  The handlers are not part of SWFUpload but are part of my website and control how
	//  my website reacts to the SWFUpload events.
	swfupload_preload_handler : preLoad,
	swfupload_load_failed_handler : loadFailed,
	file_queue_error_handler : fileQueueError,
	file_dialog_complete_handler : fileDialogComplete,
	upload_progress_handler : uploadProgress,
	upload_error_handler : uploadError,
	upload_success_handler : uploadSuccess,
	upload_complete_handler : uploadComplete,

	// Button Settings
	//button_image_url : "<?php echo $this->webroot?>plugins/SWFUpload/images/SmallSpyGlassWithTransperancy_17x18.png",
	button_placeholder_id : "spanButtonPlaceholder",
	button_width: 107,
	button_height: 38,
	button_text : 'Browse',
	button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12pt; } .buttonSmall { font-size: 10pt; }',
	button_text_top_padding: 0,
	button_text_left_padding: 18,
	button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
	button_cursor: SWFUpload.CURSOR.HAND,
	
	// Flash Settings
	flash_url : "<?php echo $this->webroot?>plugins/SWFUpload/js/swfupload.swf",
			flash9_url : "<?php echo $this->webroot?>plugins/SWFUpload/js/swfupload_fp9.swf",
    
	custom_settings : {					
		//upload_target : "divFileProgressContainer",//upload status
		type:1,//1: image, 2: gallery 
		uploadContainer:"divUploadContainer",// contain upload , use for multi upload				
		fieldName: "<?php echo 'data['.$uses[0].'][image]'?>",
		numOfMaxUpload:1  //max of upload file, 1 for single, >1 for multi, 0 for unlimit
	},
	
	// Debug Settings
    debug: false

});

scrollTopTo('addContent');
</script>

<?php } ?>
